class Product < ActiveRecord::Base	

	# ====================================================================================
	# ATTRIBUTES - PLACE
	# ====================================================================================


	# ====================================================================================
	# ASSOCIATIONS 
	# ====================================================================================
	belongs_to :user
	belongs_to :category
	belongs_to :parent, class_name: "Product", foreign_key: "parent_id"
	# belongs_to :user

	
	has_many :sub_products, class_name: "Product", foreign_key: "parent_id"
	has_many :photos, as: :photoable

	# ====================================================================================
	# VALIDATES 
	# ====================================================================================

	validates :m_name, presence: {message: I18n.t("errors.blank_product_name")}
	validates :m_description, presence: {message: I18n.t("errors.blank_description")}

	# ====================================================================================
	# STATIC 
	# ====================================================================================
	STATUS     = { pending: 0, active: 1, inactive: 2, deleted: 3 }
	VISIBILITY = { visible: 1, hidden: 2 }
	# ====================================================================================
	# SCOPES 
	# ====================================================================================
	scope :pending , -> { where(m_status: STATUS[:pending])}
	scope :active  , -> { where(m_status: STATUS[:active])}
	scope :inactive, -> { where(m_status: STATUS[:inactive])}
	scope :deleted , -> { where(m_status: STATUS[:deleted])}

	# ====================================================================================
	# INSTANCE - GET - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# INSTANCE - TODO - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# INSTANCE - FIND - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# INSTANCE - CHECK - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# CLASS - GET - FUNTIONS
	# ====================================================================================

	def self.newest limit
		self.order(created_at: :desc).limit(limit)
	end

	# ====================================================================================
	# CLASS - TODO - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# CLASS - FIND - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# CLASS - CHECK - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# CALLBACK - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# PROTECTED - FUNTIONS
	# ====================================================================================


	# ====================================================================================
	# PRIVATE - FUCTIONS
	# ====================================================================================

end
